using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VMSDISPO
    {
        public DataRow Convert2MSDISPO(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryMSDISPO(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["MSDMANDANT"] = " ".PadRight(2 ); 
         dwReturn["MSDMAT"] = " ".PadRight(14 ); 
         dwReturn["MSDVAR"] = " ".PadRight(3 ); 
         dwReturn["MSDLO"] = " ".PadRight(2 ); 
         dwReturn["MSDLB"] = " ".PadRight(2 ); 
         dwReturn["MSDMINBST"] = " ".PadRight(0 ); 
         dwReturn["MSDMAXBST"] = " ".PadRight(0 ); 
         dwReturn["MSDBESTMG"] = " ".PadRight(0 ); 
         dwReturn["MSDRW"] = " ".PadRight(0 ); 
         dwReturn["MSDBASIS"] = " ".PadRight(0 ); 
         dwReturn["MSDWDBSZT"] = " ".PadRight(0 ); 
         dwReturn["MSDSACHDSP"] = " ".PadRight(8 ); 
         dwReturn["MSDABCKL"] = " ".PadRight(1 ); 
         dwReturn["MSDDISPOKZ"] = " ".PadRight(1 ); 
         dwReturn["MSDDISPOZR"] = " ".PadRight(1 ); 
         dwReturn["MSDAUFBKZ"] = " ".PadRight(1 ); 
         dwReturn["MSDLP"] = " ".PadRight(8 ); 
         dwReturn["MSDFILLER"] = " ".PadRight(23 ); 
         dwReturn["MSDAENDZL"] = " ".PadRight(0 ); 
         dwReturn["MSDAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["MSDAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["MSDNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["MSDNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapMSDISPO(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveMSDISPO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryMSDISPO(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapMSDISPO(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertMSDISPO(dwLocal, ITXDBVERSION);
            }
            UpdateMSDISPO(dwLocal);
        }
        public void InsertMSDISPO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO MSDISPO(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryMSDISPO(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM MSDISPO WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM MSDISPO  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "MSDISPO";
            Return = Result;
            return Return;
        }
        public void DeleteMSDISPO(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM MSDISPO   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateMSDISPO(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE MSDISPO SET "
                    +"MSDMANDANT= :MSDMANDANT,"
                    +"MSDMAT= :MSDMAT,"
                    +"MSDVAR= :MSDVAR,"
                    +"MSDLO= :MSDLO,"
                    +"MSDLB= :MSDLB,"
                    +"MSDMINBST= :MSDMINBST,"
                    +"MSDMAXBST= :MSDMAXBST,"
                    +"MSDBESTMG= :MSDBESTMG,"
                    +"MSDRW= :MSDRW,"
                    +"MSDBASIS= :MSDBASIS,"
                    +"MSDWDBSZT= :MSDWDBSZT,"
                    +"MSDSACHDSP= :MSDSACHDSP,"
                    +"MSDABCKL= :MSDABCKL,"
                    +"MSDDISPOKZ= :MSDDISPOKZ,"
                    +"MSDDISPOZR= :MSDDISPOZR,"
                    +"MSDAUFBKZ= :MSDAUFBKZ,"
                    +"MSDLP= :MSDLP,"
                    +"MSDFILLER= :MSDFILLER,"
                    +"MSDAENDZL= :MSDAENDZL,"
                    +"MSDAENDBEN= :MSDAENDBEN,"
                    +"MSDAENDDAT= :MSDAENDDAT,"
                    +"MSDNEUBEN= :MSDNEUBEN,"
                    +"MSDNEUDAT= :MSDNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("MSDMANDANT", OracleType.NVarChar).Value = dwData["MSDMANDANT"].ToString(); 
          or1.Parameters.Add("MSDMAT", OracleType.NVarChar).Value = dwData["MSDMAT"].ToString(); 
          or1.Parameters.Add("MSDVAR", OracleType.NVarChar).Value = dwData["MSDVAR"].ToString(); 
          or1.Parameters.Add("MSDLO", OracleType.NVarChar).Value = dwData["MSDLO"].ToString(); 
          or1.Parameters.Add("MSDLB", OracleType.NVarChar).Value = dwData["MSDLB"].ToString(); 
          or1.Parameters.Add("MSDMINBST", OracleType.NVarChar).Value = dwData["MSDMINBST"].ToString(); 
          or1.Parameters.Add("MSDMAXBST", OracleType.NVarChar).Value = dwData["MSDMAXBST"].ToString(); 
          or1.Parameters.Add("MSDBESTMG", OracleType.NVarChar).Value = dwData["MSDBESTMG"].ToString(); 
          or1.Parameters.Add("MSDRW", OracleType.NVarChar).Value = dwData["MSDRW"].ToString(); 
          or1.Parameters.Add("MSDBASIS", OracleType.NVarChar).Value = dwData["MSDBASIS"].ToString(); 
          or1.Parameters.Add("MSDWDBSZT", OracleType.NVarChar).Value = dwData["MSDWDBSZT"].ToString(); 
          or1.Parameters.Add("MSDSACHDSP", OracleType.NVarChar).Value = dwData["MSDSACHDSP"].ToString(); 
          or1.Parameters.Add("MSDABCKL", OracleType.NVarChar).Value = dwData["MSDABCKL"].ToString(); 
          or1.Parameters.Add("MSDDISPOKZ", OracleType.NVarChar).Value = dwData["MSDDISPOKZ"].ToString(); 
          or1.Parameters.Add("MSDDISPOZR", OracleType.NVarChar).Value = dwData["MSDDISPOZR"].ToString(); 
          or1.Parameters.Add("MSDAUFBKZ", OracleType.NVarChar).Value = dwData["MSDAUFBKZ"].ToString(); 
          or1.Parameters.Add("MSDLP", OracleType.NVarChar).Value = dwData["MSDLP"].ToString(); 
          or1.Parameters.Add("MSDFILLER", OracleType.NVarChar).Value = dwData["MSDFILLER"].ToString(); 
          or1.Parameters.Add("MSDAENDZL", OracleType.NVarChar).Value = dwData["MSDAENDZL"].ToString(); 
          or1.Parameters.Add("MSDAENDBEN", OracleType.NVarChar).Value = dwData["MSDAENDBEN"].ToString(); 
          or1.Parameters.Add("MSDAENDDAT", OracleType.NVarChar).Value = dwData["MSDAENDDAT"].ToString(); 
          or1.Parameters.Add("MSDNEUBEN", OracleType.NVarChar).Value = dwData["MSDNEUBEN"].ToString(); 
          or1.Parameters.Add("MSDNEUDAT", OracleType.NVarChar).Value = dwData["MSDNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
